
function main( json, pp, hh ) {

  if ( json == null ){
        var ex = "{ exception: { message: 'no param provided'} }";
        return ex;
  }
  
  var jsonObject = new JSONObject( json );
 // return jsonObject;
  Log.debug("json=" + json);
  Log.debug("jsonObject=" + jsonObject);
 
  return checkInsert( json );

}


function checkInsert(json) {

  var records = new JSONArray();
  
  var cmd2 = "select t from UserEntity t where t.userId=:key";
  var cmd = json.getString('cmd');
  var key = json.getString('key');
  
  cmd += "'" +  key + "'";
  
  Log.debug('cmd=' + cmd);
  
  EntityManager.find(  
  cmd,  
  null,
  function(result) {
      
      for( var i = 0; i < result.size() ; ++i ) {
        
        records.put( JSONObject.wrap(result.get(i)) );
      }
      
    });
  var result = !records.isNull(0);
  var ex = "{ result: { message: 'no param provided'} }";
  var jsRes = "{ result: { message: " + result + "} }";
  return jsRes;
  //  return !records.isNull(0);
 // return records.length > 0;
 
}

